<template>
  <view class="content">
    <!-- <view class="title" @click="showcheck = !showcheck">
      <view>{{ companyName }}</view>
    </view> -->
    <titleInfo
      v-if="titleArr.length > 0"
      @showInfo="showcheck = !showcheck"
      @blackInfo="blackInfo"
      :titleArr="titleArr"
    />
    <view v-if="isCompany">
      <view
        class="items"
        v-for="(item, i) of list"
        :key="i"
        @click="lodingList(item)"
      >
        <view class="companyNameClss">
          <view>
            {{ item.companyName }}
          </view>
          <view>></view>
        </view>
        <view class="checkItems" v-if="showcheck">
          <view class="checkflex">
            <view class="titbg">重大</view>
            <view> {{ item.majorRisk || 0 }}</view>
          </view>
          <view class="checkflex">
            <view class="titbg bg2">较大</view>
            <view>{{ item.greaterRisk || 0 }}</view>
          </view>
          <view class="checkflex">
            <view class="titbg bg3">一般</view>
            <view>{{ item.generalRisk || 0 }}</view>
          </view>
          <view class="checkflex">
            <view class="titbg bg4">低</view>
            <view>{{ item.lowRisk || 0 }}</view>
          </view>
        </view>
      </view>
    </view>
    <view v-else>
      <view
        class="items"
        v-for="(item, i) of list"
        :key="i"
        @click="gogogo(item)"
      >
        <view class="flexName">
          <view> {{ item.bizName }}</view>
          <view> {{ item.bizType }}</view>
        </view>
        <!-- <view class="checkItems" v-if="showcheck">
          <view>{{ item.generalRisk || 0 }}</view>
          <view>{{ item.greaterRisk || 0 }}</view>
          <view>{{ item.lowRisk || 0 }}</view>
        </view> -->
      </view>
    </view>
  </view>
</template>

<script>
import { getUserInfoApi } from "@/apis/auth/index.js";
import { post } from "@/apis/pageNewrisk/index.js";
import titleInfo from "./titleInfo/index.vue";
export default {
  components: {
    titleInfo,
  },
  data() {
    return {
      companyName: "",
      queryParams: {
        pageNo: 1,
        pageSize: 50,
        compCode: "",
        companyName: "",
      },
      list: [],
      showcheck: false,
      isCompany: true,
      titleArr: [],
      currentChoiceCompanyCode: true
    };
  },
  created() {
    this.getUserInfo();
  },
  methods: {
    // 18615315808
    async getUserInfo() {
      const { company } = await getUserInfoApi();
      if (company.code) {
        this.companyName = company.name;
        this.queryParams.compCode = company.code;
        this.titleArr.push({
          companyName: company.name,
          companyCode: company.code,
        });
        console.log(123123, this.titleArr);
        this.getList();
      }
    },
    async getList() {
      const data = await post(
        `/admin-api/biz/riskInfo/getScreenCompanyRisk`,
        this.queryParams
      );
      if (data.list.length > 0 && this.currentChoiceCompanyCode) {
        this.isCompany = true;
        this.list = data.list;
      } else {
        this.siteList();
      }
    },
    async siteList() {
      const data = await post(
        `/admin-api/biz/risk-ent/getScreenRiskEnt`,
        this.queryParams
      );
      this.list = data.list;
      this.isCompany = false;
    },
    lodingList(item) {
      if (item.companyCode == this.queryParams.compCode) {
        this.currentChoiceCompanyCode = !this.currentChoiceCompanyCode
      }
      console.log(item.companyCode == this.queryParams.compCode, "ahhh", this.currentChoiceCompanyCode);
      if (item.companyCode) {
        this.companyName = item.companyName;
        this.queryParams.compCode = item.companyCode;
        this.titleArr.push(item);
        this.getList();
      }
    },
    blackInfo(params) {
      if (params.item.companyCode == this.queryParams.compCode) {
        this.currentChoiceCompanyCode = !this.currentChoiceCompanyCode
      }
      this.queryParams.compCode = params.item.companyCode;
      this.titleArr = params.arrList;
      this.getList();
    },
    gogogo(item) {
      uni.navigateTo({
        url: `/riskPointManagement/index?bizCode=${item.bizCode}`,
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.content {
  width: 92%;
  margin: 0 auto;
  color: #333;
  font-family: Source Han Sans CN;
  .title {
    width: 100%;
    text-align: center;
    font-size: 0.9rem;
    margin: 2vh 0;
  }
  .items {
    width: 100%;
    padding: 10rpx;
    box-sizing: border-box;
    box-shadow: 6rpx 8rpx 8rpx #dedede;
    margin-bottom: 30rpx;
    border-radius: 8rpx;
    .companyNameClss,
    .flexName {
      display: flex;
      padding: 16rpx 18rpx;
      font-size: 0.85rem;
      color: #333;
      justify-content: space-between;
    }
    .checkItems {
      width: 100%;
      display: flex;
      justify-content: space-between;
      font-size: 0.85rem;
      margin: 1vh 0;
      padding: 16rpx 18rpx;
      box-sizing: border-box;
      align-items: center;
      .checkflex {
        width: 22%;
        display: flex;
        justify-content: space-between;
        align-items: center;
        .titbg {
          width: 60rpx;
          height: 60rpx;
          font-size: 0.7rem;
          border-radius: 50%;
          line-height: 60rpx;
          background: #d93a34;
          text-align: center;
          color: #fff;
        }
        .bg2 {
          background: #ee8542;
        }
        .bg3 {
          background: #e1d74b;
        }
        .bg4 {
          background: #499ee1;
        }
      }
    }
  }
}
</style>